/*
 * Copyright (c) 2017-2019, AEye, Inc.
 * All rights reserved.
 */

#ifndef RANGING_FRAME_DATA_H
#define RANGING_FRAME_DATA_H

#include <cstddef>
#include <cstdint>
#include <memory>

#include "AEyeSensorAPI.h"

class RangingFrameData {
public:
  RangingFrameData();

  void addPoints(const aeye::PointReturnsBody& packetBody, const uint8_t* pData, size_t numPoints);

  void reset() noexcept;

  bool complete() const noexcept;

  unsigned int getFrameId() const noexcept;

  void setFrameId(unsigned int _frameId) noexcept;

  void setTime(unsigned int _tsSec, unsigned int _tsuSec) noexcept;

  inline unsigned int getTimeSec() const noexcept { return tsSec; }
  inline unsigned int getTimeuSec() const noexcept { return tsuSec; }

  unsigned short seqCount() const noexcept;

  const aeye::AEyePoint *getPoints() const noexcept;
  unsigned long getTotalNumPoints() const noexcept;

  unsigned short getFlexFormatDataFlags() const noexcept;

private:
  static constexpr size_t MAX_LIDAR_WIDTH  = 2561;
  static constexpr size_t MAX_LIDAR_HEIGHT = 1361;
  static constexpr uint8_t MAX_NUM_ECHOES = 2;
  static constexpr size_t MAX_LIDAR_POINTS = MAX_LIDAR_WIDTH * MAX_LIDAR_HEIGHT * MAX_NUM_ECHOES;
  size_t currentMaxPoints = MAX_LIDAR_POINTS;

  unsigned int                       frameId;
  unsigned short                     seqCounter;
  unsigned short                     seqTotal;
  bool                               isValid;
  unsigned short                     flexFormatDataFlags;
  std::unique_ptr<aeye::AEyePoint[]> points;
  unsigned long                      totalNumPoints;
  unsigned int                       tsSec;
  unsigned int                       tsuSec;

  void reallocate(size_t numPoints);
};



#endif //RANGING_FRAME_DATA_H
